<!DOCTYPE html>
<html>
<head>

    {include file="Public/header"}

    <link rel="stylesheet" href="__STATIC__/layout/css/gyq.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 4px;
        }
        .note-editable {
            height: 150px
        }
    </style>
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
</head>

<body style="color:#333;padding:3px;font-size: 12px" class="x_sorll">
<!-- 标题 -->
<div class="page-heade">
    <h2 class="title_color text-center">添加销售订单</h2>
</div>
<!-- 标题 -->
<div>
    <form action="" class="form-inline" id="form1">
        <table class="row-margin-top tab-content table-bordered table" border="1" style="margin-bottom:0">
            <tr>
                <td style="min-width: 120px;width: 120px" class="text-center"><label for="">客户类型<span class="colorRed">*</span></label></td>
                <td style="min-width: 220px;width: 220px">
                    <div class="form-group">
                        <label class="radio-inline">
                            <input type="radio" {if !isset($data)||$data.cusType==1}checked{/if} name="cusType" id="cusType"  value="1">经销商
                        </label>
                    </div>
                    {if !$isnet}
                    <div class="form-group">
                        <label class="radio-inline">
                            <input type="radio" {if isset($data)&&$data.cusType==2}checked{/if} name="cusType"   value="2">网点
                        </label>
                    </div>
                    {/if}
                </td>
                <td style="min-width: 120px;width: 120px" class="text-center"><label for="">客户名称<span class="colorRed">*</span>:</label>
                </td>
                <td colspan="3">
                    <div style="width:140px;height:30px;float:left;">
                        <div class="input-group" id="cusName_input" {if isset($data)}style="display: none;"{/if} >
                            <input type="text" placeholder="请输入关键字或空格查询" class="form-control" id="cusName" >
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                        <div id="cusName_queding" class="selectedOnlyOne" {if !isset($data)}style="display: none;"{/if}>
                            <input type="hidden" name="cusName" value="{if isset($data)}{$data.cusName}{/if}">
                            <span class="inin">{if isset($data)}{$data.cusName_name}{/if}</span>
                            <span class="close">×</span>
                        </div>
                    </div>
                    <a href="javascript:;" id="selectCus" style="float:left;">选择<span class="helpText">帮</span></a>
                </td>
            </tr>
            <tr>
                <td style="min-width: 120px;width: 120px" class="text-center">
                    <label for="">开发票类型</label>
                </td>
                <td style="min-width: 220px;width: 220px">
                    <div class="form-group" id="kfplx">
                        <label class="radio-inline">
                            <input type="radio" checked name="fpType" id="inlineRadio11" value="{if isset($data)&&$data.fpType}{$data.fpType}{else}1{/if}"><span id="fpType">{if isset($data)&&$data.fpType==2}增值税发票{else}普通发票{/if}</span>
                        </label>
                    </div>
                </td>
                <td style="min-width: 120px;width: 120px" class="text-center">
                    <label for="" class="form-label">建议发货日期<span class="colorRed">*</span>：</label>
                </td>
                <td colspan="3">
                    <input type="text" class="form-control layer-date" name="jyfhrq" onclick="laydate()" id="startTime" value="{if isset($data)}{$data.jyfhrq}{else}{:date('Y-m-d',strtotime('+10 days'))}{/if}">
                </td>

            </tr>
            <tr>
                <td style="min-width: 120px;width: 120px" class="text-center"><label for="">渠道优惠政策：</label>
                </td>
                <td  style="min-width: 220px;width: 220px">

                    <div id="hasyh" {if isset($data)&&$data.yhPolicy||isset($qdyhzc)&&$qdyhzc>0}{else}style="display:none;"{/if}>
                        <div style="width:140px;height:30px;float:left;">
                            <div class="input-group" id="yh_input" {if isset($data)&&$data.yhPolicy}style="display: none;"{/if}>
                            <input type="text" placeholder="请输入关键字或空格查询" class="form-control" id="yhPolicy" value="">
                            <div class="input-group-btn">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                        <div id="yh_queding" class="selectedOnlyOne"  {if isset($data)&&$data.yhPolicy}{else}style="display: none;"{/if}>
                        <input type="hidden" name="yhPolicy" value="{if isset($data)&&$data.yhPolicy}{$data.yhPolicy}{/if}" >
                        <span class="inin">{if isset($data)&&$data.yhPolicy}{$data.yhPolicyName}{/if}</span>
                        <span class="close">×</span>
                    </div>
                    </div>
                    <a href="javascript:;" id="selectyh" style="float:left;">选择<span class="helpText">帮</span></a>
                    </div>
                    <div id="noyh" {if isset($data)&&$data.yhPolicy||isset($qdyhzc)&&$qdyhzc>0}style="display:none;"{else}{/if}>
                        无对应优惠渠道政策
                    </div>
                </td>
                <td style="min-width: 120px;width: 120px" class="text-center">
                    <label for="" class="form-label">收货信息<span class="colorRed">*</span>：</label>
                </td>
                <td colspan="3">
                    <div class="form-group">
                        <label for="" class="form-label">收货地址：</label>
                        <input type="text" class="form-control" name="shdz" {if isset($data)}value="{$data.shdz}"{/if}>
                    </div>
                    <div class="form-group">
                        <label for="" class="form-label">收货人：</label>
                        <input type="text" class="form-control" name="shr" {if isset($data)}value="{$data.shr}"{/if}>
                    </div>
                    <div class="form-group">
                        <label for="" class="form-label">电话：</label>
                        <input type="text" class="form-control" name="dh" {if isset($data)}value="{$data.dh}"{/if}>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="6" style="background-color: RGB(255,243,189);">
                    根据公司规定，搭赠金额+补货金额+补费金额（核销费用转订单款）占订单销售额不允许超过30.0%
                </td>
            </tr>
            <tr>
                <td colspan="6">
                    <button class="btn btn-info btn-sm" type="button" id="addsall">添加销售订单明细</button>
                    （至少添加一条物料明细）
                    {if !$isbuhuo}
                    <button class="btn btn-info btn-sm" type="button" id="addhuobu">添加货补订单明细</button>
                    （备注：根据需货补的核销单添加货补明细）
                    {/if}
                    {if !$isbufei}
                    <button class="btn btn-info btn-sm" type="button" id="addbuhuo">添加补费订单明细</button>
                    （备注：选择核销单冲抵订单金额）
                    {/if}
                </td>
            </tr>
        </table>
        <table class=" table table-striped table-bordered text-center ad_table" id="jxb">
            <thead>
            <tr class="info">
                <th class="text-center font-bold" colspan="16">
                    成品销售订单 <a href="javascript:;" style="color:red" onclick="$('#jxb').hide();$('#wzb').show();">（查看完整版订单）</a>
                </th>
            </tr>
            <tr class="info">
                <th class="text-center">明细编号</th>
                <th class="text-center">操作</th>
                <th class="text-center">产品编码</th>
                <th class="text-center" style="color: blue">产品名称<span>↓</span></th>
                <th class="text-center">对应订单明细编号</th>
                <th class="text-center">对应核销单明细编号</th>
                <th class="text-center">单位</th>
                <th class="text-center">原供价(元)</th>
                <th class="text-center">现供价(元)</th>
                <th class="text-center">类型</th>
                <th class="text-center">订货数量</th>
                <th class="text-center">搭赠数量</th>
                <th class="text-center">原金额(元)</th>
                <th class="text-center">应收金额(元)</th>
                <th class="text-center qdyhl">渠道优惠政策金额</th>
                <th class="text-center">备注</th>
            </tr>
            </thead>
            {if isset($data)}
            {volist name="data.list" id="row"}
            <tr>
                <td>
                    {$data.sn}-{$row.sn}
                </td>
                <td>
                {if $row.kind==2}
                {else}
                    <button type="button" class="btn btn-sm btn-primary xiugai" data-link="{:url('upDetail',['id'=>$row.id])}">修改</button>
                    <button type="button" class="btn btn-sm btn-danger shanchu" data-link="{:url('deDetail',['id'=>$row.id])}">删除</button>
                {/if}
                </td>
                <td>{$row.prod_sn}</td>
                <td>{$row.prod_name}{if $row.dyddmxid}<span style="display: inline-block;padding:1px;color:red;border:1px solid red;line-height: 1rem;font-weight: bold;">赠</span>{/if}</td>
                <td>{$row.dyddmxid}</td>
                <td>&nbsp;</td>
                <td>{$row.unit}</td>
                <td>{$row.ygj}</td>
                <td>{$row.xgj}</td>
                <td>{if $row.xslx==1}销售{elseif $row.xslx==2}搭赠{elseif $row.xslx==3}货补{elseif $row.xslx==4}补费{/if}</td>
                <td>{$row.num}</td>
                <td>{$row.dzsl}</td>
                <td>{$row.yje}</td>
                <td>{$row.ysje}</td>
                <td class="qdyhl">{$row.qdyhje}</td>
                <td>{$row.beizhu}</td>
            </tr>
            {/volist}
            {volist name="data.huobu" id="row"}
            <tr>
                <td>
                    {$data.sn}-{$row.sn}
                </td>
                <td>
                    <button type="button" class="btn btn-sm btn-primary xiugai" data-link="{:url('upHuobu',['id'=>$row.id])}">修改</button>
                    <button type="button" class="btn btn-sm btn-danger shanchu" data-link="{:url('deHuobu',['id'=>$row.id])}">删除</button>
                </td>
                <td>{$row.prod_sn}</td>
                <td>{$row.prod_name} <span style="display: inline-block;padding:1px;color:red;border:1px solid red;line-height: 1rem;font-weight: bold;">赠</span></td>
                <td> </td>
                <td>{$row.hxdbh}</td>
                <td>{$row.unit}</td>
                <td>{$row.ygj}</td>
                <td>{$row.xgj}</td>
                <td>补货</td>
                <td></td>
                <td>{$row.num}</td>
                <td>{$row.yje}</td>
                <td>{$row.ysje}</td>
                <td class="qdyhl"></td>
                <td>{$row.beizhu}</td>
            </tr>
            {/volist}
            {/if}
            <tr class="font-bold text-right">
                <td></td>
                <td></td>
                <td colspan="4">小计</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>{if isset($zj1)}{$zj1}{/if}</td>
                <td>{if isset($zj2)}{$zj2}{/if}</td>
                <td>{if isset($zj3)}{$zj3}{/if}</td>
                <td>{if isset($zj4)}{$zj4}{/if}</td>
                <td class="qdyhl"></td>
                <td></td>
            </tr>
        </table>
        <table class=" table table-striped table-bordered text-center ad_table" id="wzb" style="display: none;">
            <thead>
                <tr class="info">
                    <th colspan="20" class="text-center font-bold">成品销售订单<a href="javascript:;" style="color:red" onclick="$('#jxb').show();$('#wzb').hide();">（查看精简版版订单）</a></th>
                </tr>
                <tr class="info">
                    <th>明细编号</th>
                    <th>操作</th>
                    <th>品类</th>
                    <th>产品编码</th>
                    <th>产品名称</th>
                    <th>对应订单<br>明细编号</th>
                    <th>对应核销单<br>明细编号</th>
                    <th>规格</th>
                    <th>条形码</th>
                    <th>单位</th>
                    <th>原供价(元)</th>
                    <th>现供价(元)</th>
                    <th>类型</th>
                    <th>订货数量</th>
                    <th>搭赠数量</th>
                    <th>原金额(元)</th>
                    <th>应收金额(元)</th>
                    <th>体积(立方米)</th>
                    <th>重量(吨)</th>
                    <th>备注</th>
                </tr>
            </thead>
            <tbody>
            {if isset($data)}
            {volist name="data.list" id="row"}
            <tr>
                <td>
                    {$row.mxbh}
                </td>
                <td>
                    <button type="button" class="btn btn-primary xiugai" data-link="{:url('upDetail',['id'=>$row.id])}">修改</button>
                    <button type="button" class="btn btn-danger shanchu" data-link="{:url('deDetail',['id'=>$row.id])}">删除</button>
                </td>
                <td>
                    {$row.category}
                </td>
                <td>
                    {$row.prod_sn}
                </td>
                <td>
                    {$row.prod_name}
                </td>
                <td>
                    {$row.order_sn}
                </td>
                <td>
                    {$row.order_sn}
                </td>
                <td>
                    {$row.format}
                </td>
                <td>
                    {$row.pro_sku}
                </td>
                <td>
                    {$row.unit}
                </td>
                <td>
                    {$row.ygj}
                </td>
                <td>
                    {$row.xgj}
                </td>
                <td>
                    {if $row.xslx==1}销售{elseif $row.xslx==2}搭赠{elseif $row.xslx==3}货补{elseif $row.xslx==4}补费{/if}
                </td>
                <td>
                    {$row.num}
                </td>
                <td>
                    {$row.dzsl}
                </td>
                <td>
                    {$row.yje}
                </td>
                <td>
                    {$row.ysje}
                </td>
                <td>{$row.box_volume}</td>
                <td>{$row.weight}</td>
                <td>{$row.beizhu}</td>
            </tr>
            {/volist}
            {volist name="data.huobu" id="row"}
            <tr>
                <td>
                    {$row.mxbh}
                </td>
                <td>
                    <button type="button" class="btn btn-primary xiugai" data-link="{:url('upHuobu',['id'=>$row.id])}">修改</button>
                    <button type="button" class="btn btn-danger shanchu" data-link="{:url('deHuobu',['id'=>$row.id])}">删除</button>
                </td>
                <td>
                    {$row.category}
                </td>
                <td>
                    {$row.prod_sn}
                </td>
                <td>
                    {$row.prod_name}
                </td>
                <td>
                    {$row.order_sn}
                </td>
                <td>
                    {$row.order_sn}
                </td>
                <td>
                    {$row.format}
                </td>
                <td>
                    {$row.pro_sku}
                </td>
                <td>
                    {$row.unit}
                </td>
                <td>
                    {$row.yje}
                </td>
                <td>{$row.ysje}
                </td>
                <td>
                    补货
                </td>
                <td>{$row.num}</td>
                <td></td>
                <td>{$row.yje}</td>
                <td>{$row.ysje}</td>
                <td>{$row.box_volume}</td>
                <td>{$row.weight}</td>
                <td>{$row.beizhu}</td>
            </tr>
            {/volist}
            {/if}
            <tr>
                <td>
                </td>
                <td colspan="8" class="text-right text-bold">小计：</td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td>{if isset($zj1)}{$zj1}{/if}</td>
                <td>{if isset($zj2)}{$zj2}{/if}</td>
                <td>{if isset($zj3)}{$zj3}{/if}</td>
                <td>{if isset($zj4)}{$zj4}{/if}</td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            </tbody>
        </table>
{if isset($data.bufei)&&count($data.bufei)>0}
        <table class="table table-striped table-bordered text-center ad_table">
            <thead>
            <tr class="info">
                <th colspan="7" class="text-center font-bold">补费明细</th>
            </tr>
            <tr class="info">
                <th>明细编号</th>
                <th>操作</th>
                <th>对应核销单编号</th>
                <th>类型</th>
                <th>补费金额(元)</th>
                <th>应收金额(元)</th>
                <th>备注</th>
            </tr>
            </thead>
            <tbody>

            {volist name="data.bufei" id="row"}
            <tr>
                <td>
                    {$row.mxbh}
                </td>
                <td>
                    <button type="button" class="btn btn-primary btn-sm xiugai" data-link="{:url('upBufei',['id'=>$row.id])}">修改</button>
                    <button type="button" class="btn btn-danger btn-sm shanchu" data-link="{:url('deBufei',['id'=>$row.id])}">删除</button>
                </td>
                <td>
                    <a href="{:url('Tihexiao/view',['id'=>$row.hxdmxbh])}" class="J_menuItem">{$row.hxdbh}</a>
                </td>
                <td>
                    补费
                </td>
                <td>
                    {$row.bfje}
                </td>
                <td>
                    -{$row.bfje}
                </td>
                <td>
                    {$row.beizhu}
                </td>
            </tr>
            {/volist}

            <tr>
                <td>

                </td>
                <td colspan="3">

                </td>
                <td>
                    {if isset($xj)}{$xj}{/if}
                </td>
                <td>
                    -{if isset($xj)}{$xj}{/if}
                </td>
                <td>
                </td>
            </tr>
            </tbody>
        </table>
        {/if}
        <table class="row-margin-top table table-bordered">
            <tr class="font-bold">
                <td style="min-width: 200px;width: 200px">订单总应收金额：</td>
                <td><span id="ddyszje">{if isset($data)}{$data.yszje}{/if}</span><input type="hidden" name="yszje" value="{if isset($data)}{$data.yszje}{/if}"></td>
            </tr>
        </table>
        <table class="table table-bordered">
            <tr>
                <td class="font-bold" style="min-width: 200px;width: 200px" rowspan="3">
                    <label for=""  class="form-label">注意事项<span class="colorRed">*</span>：</label></td>
                <td rowspan="3">
                    <textarea name="zysx" id="zysx" class="form-control" style="user-select:none;width: 60%"  rows="3">{if isset($data)}{$data.zysx}{/if}</textarea>
                    <span style="vertical-align: bottom;">(300)</span>
                </td>
            </tr>
        </table>

        <div class="form-group white-bg" style="margin:20px 10px 20px 20px;">
            {if isset($attach)}
            <ul class="list-group">
                {volist name="attach" id="row"}
                <li class="list-group-item">
                    <a class="badge badge-primary removeIt" data-id="{$row.id}">移除</a>
                    <a href="{$row.path}" target="_blank">{$row.file_name}</a></li>
                {/volist}
            </ul>
            {/if}
            <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list"></div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach">
                <input type="hidden" name="remove" id="remove">
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>
        {if isset($data)}
            {if $data.status==2}
                 <div class="" style="margin:20px 10px 20px 20px;">
         <table class="table table-bordered text-left bud_hei">
            <tr class="info">
                <th class="text-left font-bold">审批意见</th>
            </tr>
            {volist name="logs" id="l"}
          <tr>
              <td>{$l.USERNAME} 审批动作：{$l.MEMO}；审批意见：{if $l.COMMENTS}{$l.COMMENTS}{else/}无{/if}(审批时间：{$l.ACTIONTIME})</td>
          </tr>
          
          {/volist}
      </table>
      </div>
            {/if}
        {/if}
        <div class="row sub_btn" style="width:100%;text-align:center;padding: 20px 0">
            {if !isset($data)}
            <input type="hidden" name="savet" id="savet"/>
            <input type="submit" class="btn btn-success save" savet="1" value="保存为草稿">
            <input type="submit" class="btn btn-info save" savet="3" value="保存并提交工作流">
            {else}
                {if $data.status==2}
                <input type="hidden" id="nodeKey" name="nodeKey"/>
                  <input type="hidden" id="selectId" name="selectId"/>
                  <input type="hidden" id="selectName" name="selectName"/>
                    {volist name="btn.nextNodes" id="b"}
                      {if $b.nodeName=='结束'}
                      <input type="button" class="btn-danger btn" onclick="zuofei('{$b.nodeKey}','{$b.selectId}','{$b.selectName}')" value="点此作废"/>
                      {else/}
                      <input type="button" class="btn-info btn" onclick="baocun('{$b.nodeKey}','{$b.selectId}','{$b.selectName}')" value="保存并提交工作流"/>
                      {/if}
                    {/volist}
                {else}
                <input type="hidden" name="savet" id="savet"/>
            <input type="submit" class="btn btn-success save" savet="1" value="保存为草稿">
            <input type="submit" class="btn btn-info save" savet="3" value="保存并提交工作流">
                {/if}
            {/if}
            <input type="button" class="btn btn-warning" value="返回" id="fanhui">
        </div>
        <input type="hidden" name="id" id="id" value="{if isset($id)}{$id}{/if}">
    </form>
</div>
<!-- 全局js -->
{include file="Public/footer"}
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script>
    var link1 = '{:url("jxsjson")}'
    var link2 = '{:url("selectJXS")}'
</script>
<script>
var fr={$from};
 function baocun(nodeKey,selectId,selectName){
  $("#nodeKey").val(nodeKey)
  $("#selectId").val(selectId)
  $("#selectName").val(selectName)
   $.ajax({
          cache: true,
          type: "POST",
          url:"{:url('baocunchuli')}",
          data:$('#form1').serialize(),// 你的formid
          async: false,
          error: function(request) {
            alert("Connection error");
          },
          success: function(data) {
            //alert(data);
            //var res=JSON.parse(data);
                    var res1=JSON.parse(data);
                            if(res1["state"]==1){
                              swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                                },function(){
                                  if(fr==1)
                                        location.href="{:url('index')}"
                                  else
                                        location.href="{:url('Workflowdb/index')}"
                                });

                          }else{
                            swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                            });
                          }           
          }
        });
}
function zuofei(nodeKey,selectId,selectName){
  $("#nodeKey").val(nodeKey)
  $("#selectId").val(selectId)
  $("#selectName").val(selectName)
   $.ajax({
          cache: true,
          type: "POST",
          url:"{:url('zuofeichuli')}",
          data:$('#form1').serialize(),// 你的formid
          async: false,
          error: function(request) {
            alert("Connection error");
          },
          success: function(data) {
           // alert(data);
            //var res=JSON.parse(data);
                    var res1=JSON.parse(data);
                            if(res1["state"]==1){
                              swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                                },function(){
                                   if(fr==1)
                                        location.href="{:url('index')}"
                                    else
                                        location.href="{:url('Workflowdb/index')}"
                                  //parent.layer.close(parent.layer.getFrameIndex(window.name))
                                  //
                                });

                          }else{
                            swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                            });
                          }         
          }
        });
}
//取消优惠
function clearyh(){
    //alert(1)
    var oid=$("#id").val();
    if(oid!=""){
        $.post('{:url("clearyh")}',{oid:oid},function(data){
            //alert(data);
            data=JSON.parse(data)
                 if(data.success){
                        location.reload()
                    }
        })
    }
}

function qudaoyouhuipipei(){
    //获取订单号，渠道号
    var oid=$("#id").val();
    var qid=$("[name='yhPolicy']").val();
    if(oid!=""){
        $.post('{:url("qdyhzcxz")}',{qdyh_id:qid,order_id:oid},function (data) {
                data=JSON.parse(data)
                 if(data.success){
                        location.reload()
                    }
                    //alert(data)
                })
    }
}
function gonet(nid){
    var oid=$("#id").val();
    if(oid!=""){
       if(confirm("客户变更将会导致产品价格变动和渠道政策失效，是否确认要修改客户")){
            $.post("{:url('changecus')}",{cusType:2,cusName:nid,oid:oid},function(data){
                 data=JSON.parse(data)
                 if(data.success){
                        location.reload()
                    }
            })
       }else{
            location.reload() 
       }
    }else{
        $.post("{:url('getnet')}",{nid:nid},function(re){
        var re=JSON.parse(re);
        $('[name=shdz]').val(re["lgs_rcv_addr"])
        $('[name=shr]').val(re["lgs_rcv_one"])
        $('[name=dh]').val(re["lgs_rcv_phone"])
        var jid=re["jxs"];
        $.post('{:url("hasyh")}',{jxs_id:re["jxs"]},function (data) {
        // alert(data)
        if(data.success){
            $("#yhPolicy").bsSuggest('destroy')
            $("#yhPolicy").bsSuggest({
                url: '{:url("yhPolicy")}?jxs_id='+jid,
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
             }).on('onDataRequestSuccess', function (e, result) {
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword) {
                $('#yh_queding').find('.inin').html(keyword.key)
                $('#yh_queding').find('input').val(keyword.id)
                $('#yh_queding').show()
                $('#yh_input').hide()
                $('#yh_input').find('input').val('')
                qudaoyouhuipipei()
                    //查询渠道优惠政策限制规则
               /* $.post('{:url("qdyhzcxz")}',{qdyh_id:keyword.id,order_id:$('#id').val()},function (data) {
                    if(data.success){
                        location.reload()
                    }
                },'json')*/
            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });
                //关闭渠道优惠政策选择
            $('#yh_queding .close').click(function () {
                $(this).closest('#yh_queding').hide().find('.inin').html('')
                $('#yh_queding').find('input').val('')
                $('#yh_input').show().find('input').val('')
                clearyh();
            })
            //弹出渠道优惠政策树
            $('#selectyh').off('click')
            $('#selectyh').on('click',function () {
                //alert(1);
            top.layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("open/yhpolicy")}?jxs_id='+jid,
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var id =  a.find("#renyuan").val();
                    var name =  a.find("#renyuanname").val();
                    if(id){
                        $('#yh_queding').find('.inin').html(name)
                        $('#yh_queding').find('input').val(id)
                        $('#yh_queding').show()
                        $('#yh_input').hide()
                        $('#yh_input').find('input').val('')
                        qudaoyouhuipipei()
                    }
                    top.layer.close(i)
                    }
            })
            return  false
        })
        $('#hasyh').show()
        $('#noyh').hide()
    }else{
        $('#hasyh').hide()
        $('#noyh').show()
    }

    $('#hide1').show()
    },'json')   
    })
    }
    
}
function gojxs(jid){
    var oid=$("#id").val();
    if(oid!=""){
       if(confirm("客户变更将会导致产品价格变动和渠道政策失效，是否确认要修改客户")){
            $.post("{:url('changecus')}",{cusType:1,cusName:jid,oid:oid},function(data){
                 data=JSON.parse(data)
                 if(data.success){
                        location.reload()
                    }
            })
       }else{
            location.reload() 
       }
    }else{
        $.post("{:url('getjxs')}",{jid:jid},function(re){
            var re=JSON.parse(re)
            $('[name=shdz]').val(re["bs_rcv_addr"])
            $('[name=shr]').val(re["bs_rcv_one"])
            $('[name=dh]').val(re["bs_rcv_phone"])

        })
        $.post('{:url("hasyh")}',{jxs_id:jid},function (data) {
            // alert(data)
            if(data.success){
                $("#yhPolicy").bsSuggest('destroy')
                $("#yhPolicy").bsSuggest({
                    url: '{:url("yhPolicy")}?jxs_id='+jid,
                    effectiveFields: ["id", "title"],
                    searchFields: [ "title"],
                    effectiveFieldsAlias: {title: "名称"},
                    ignorecase: true,
                    showHeader: true,
                    showBtn: false,     //不显示下拉按钮
                    delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                    idField: "id",
                    keyField: "title",
                    clearable: true
                 }).on('onDataRequestSuccess', function (e, result) {
                    console.log('onDataRequestSuccess: ', result);
                }).on('onSetSelectValue', function (e, keyword) {
                    $('#yh_queding').find('.inin').html(keyword.key)
                    $('#yh_queding').find('input').val(keyword.id)
                    $('#yh_queding').show()
                    $('#yh_input').hide()
                    $('#yh_input').find('input').val('')
                    qudaoyouhuipipei()
                        //查询渠道优惠政策限制规则
                   /* $.post('{:url("qdyhzcxz")}',{qdyh_id:keyword.id,order_id:$('#id').val()},function (data) {
                        if(data.success){
                            location.reload()
                        }
                    },'json')*/
                }).on('onUnsetSelectValue', function () {
                    console.log("onUnsetSelectValue");
                });
                    //关闭渠道优惠政策选择
                $('#yh_queding .close').click(function () {
                    $(this).closest('#yh_queding').hide().find('.inin').html('')
                    $('#yh_queding').find('input').val('')
                    $('#yh_input').show().find('input').val('')
                    clearyh();
                })
                //弹出渠道优惠政策树
                $('#selectyh').off('click')
                $('#selectyh').on('click',function () {
                    //alert(1);
                top.layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:'{:url("open/yhpolicy")}?jxs_id='+jid,
                    btn:['确定','关闭'],
                    yes:function (i,o) {
                        var a = $(o).find('iframe').contents()
                        var id =  a.find("#renyuan").val();
                        var name =  a.find("#renyuanname").val();
                        if(id){
                            $('#yh_queding').find('.inin').html(name)
                            $('#yh_queding').find('input').val(id)
                            $('#yh_queding').show()
                            $('#yh_input').hide()
                            $('#yh_input').find('input').val('')
                            qudaoyouhuipipei()
                        }
                        top.layer.close(i)
                        }
                })
                return  false
            })
            $('#hasyh').show()
            $('#noyh').hide()
        }else{
            $('#hasyh').hide()
            $('#noyh').show()
        }

        $('#hide1').show()
        },'json')
    }
       
}
    $('[name=cusType]').on('click',function () {
        if ($(this).val() == 1) {
            $('#kfplx').show()
            $('#cusName_queding').hide()
            $('#cusName_queding input').val('')
            $('#cusName_queding .inin').html('')
            $('#cusName_input').show()
            $('#cusName_input input').val('')
            //经销商搜索自动补全
            var cusName = [];
            $("#cusName").bsSuggest('destroy')
            $("#cusName").bsSuggest({
                url: link1,
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onDataRequestSuccess', function (e, result) {
               // alert(result.value)
                $(this).data('cusName',escape(result.value))
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword) {
                $('#cusName_queding').find('.inin').html(keyword.key)
                $('#cusName_queding').find('input').val(keyword.id)
                $('#cusName_queding').show()
                $('#cusName_input').hide()
                gojxs(keyword.id)
                //var cusName = unescape($(this).data('cusName'))
               // alert(cusName)
               /* for(var i = 0;i<cusName.length;i++){
                    if(cusName[i].id==keyword.id){
                        $('[name=shdz]').val(cusName[i].lgs_rcv_addr)
                        $('[name=shr]').val(cusName[i].lgs_rcv_one)
                        $('[name=dh]').val(cusName[i].bs_rcv_phone)
                        // alert(cusName[i].invoicetype)
                        $('[name=fpType]:checked').val(cusName[i].invoicetype)
                        $('#fpType').html(cusName[i].invoicetype==1?'普通发票':'增值税发票')
                        //判断经销商是否有渠道优惠政策
                        $.post('{:url("hasyh")}',{jxs_id:keyword.id},function (data) {
                           // alert(data)
                            if(data.success){
                                $("#yhPolicy").bsSuggest('destroy')
                                $("#yhPolicy").bsSuggest({
                                    url: '{:url("yhPolicy")}?jxs_id='+keyword.id,
                                    effectiveFields: ["id", "title"],
                                    searchFields: [ "title"],
                                    effectiveFieldsAlias: {title: "名称"},
                                    ignorecase: true,
                                    showHeader: true,
                                    showBtn: false,     //不显示下拉按钮
                                    delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                                    idField: "id",
                                    keyField: "title",
                                    clearable: true
                                }).on('onDataRequestSuccess', function (e, result) {
                                    console.log('onDataRequestSuccess: ', result);
                                }).on('onSetSelectValue', function (e, keyword) {
                                    $('#yh_queding').find('.inin').html(keyword.key)
                                    $('#yh_queding').find('input').val(keyword.id)
                                    $('#yh_queding').show()
                                    $('#yh_input').hide()
                                    $('#yh_input').find('input').val('')
                                    //查询渠道优惠政策限制规则
                                    $.post('{:url("qdyhzcxz")}',{qdyh_id:keyword.id,order_id:$('#id').val()},function (data) {
                                        if(data.success){
                                            location.reload()
                                        }
                                    },'json')
                                }).on('onUnsetSelectValue', function () {
                                    console.log("onUnsetSelectValue");
                                });
                                //关闭渠道优惠政策选择
                                $('#yh_queding .close').click(function () {
                                    $(this).closest('#yh_queding').hide().find('.inin').html('')
                                    $('#yh_queding').find('input').val('')
                                    $('#yh_input').show().find('input').val('')
                                })
                                //弹出渠道优惠政策树
                                $('#selectyh').off('click')
                                $('#selectyh').on('click',function () {
                                    top.layer.open({
                                        type:2,
                                        area:['60%','60%'],
                                        maxmin:true,
                                        content:'{:url("open/yhpolicy")}?jxs_id='+keyword.id,
                                        btn:['确定','关闭'],
                                        yes:function (i,o) {
                                            var a = $(o).find('iframe').contents()
                                            var id =  a.find("#renyuan").val();
                                            var name =  a.find("#renyuanname").val();
                                            if(id){
                                                $('#yh_queding').find('.inin').html(name)
                                                $('#yh_queding').find('input').val(id)
                                                $('#yh_queding').show()
                                                $('#yh_input').hide()
                                                $('#yh_input').find('input').val('')
                                            }
                                            top.layer.close(i)
                                        }
                                    })
                                    return  false
                                })
                                $('#hasyh').show()
                                $('#noyh').hide()
                            }else{
                                $('#hasyh').hide()
                                $('#noyh').show()
                            }

                            $('#hide1').show()
                        },'json')
                    }
                }*/

            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });

            $('#selectCus').off('click')
            //弹出经销商树
            $('#selectCus').click(function () {
                top.layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content:link2,
                    btn:['确定','关闭'],
                    yes:function (i,o) {
                        var a = $(o).find('iframe').contents()
                        var id =  a.find("#renyuan").val();
                        var name =  a.find("#renyuanname").val();
                        if(id){
                            $('#cusName_queding').find('.inin').html(name)
                            $('#cusName_queding').find('input').val(id)
                            $('#cusName_queding').show()
                            $('#cusName_input').hide()

                            gojxs(id)
                        }
                        top.layer.close(i)
                    }
                })
                return  false
            })
        }else {
            $('#kfplx').hide()
            $('#cusName_queding').hide()
            $('#cusName_queding input').val('')
            $('#cusName_queding .inin').html('')
            $('#cusName_input').show()
            $('#cusName_input input').val('')
            $("#cusName").bsSuggest('destroy')
            $("#cusName").bsSuggest({
                url: '{:url("bs/net")}',
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onDataRequestSuccess', function (e, result) {
                cusName = result.value
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword) {
                $('#cusName_queding').find('.inin').html(keyword.key)
                $('#cusName_queding').find('input').val(keyword.id)
                $('#cusName_queding').show()
                $('#cusName_input').hide()
                gonet(keyword.id)
               /* for(var i = 0;i<cusName.length;i++){
                    if(cusName[i].id==keyword.id){
                        $('[name=shdz]').val(cusName[i].lgs_rcv_addr)
                        $('[name=shr]').val(cusName[i].lgs_rcv_one)
                        $('[name=dh]').val(cusName[i].bs_rcv_phone)
                        // alert(cusName[i].invoicetype)
                        $('[name=fpType]:checked').val(cusName[i].invoicetype)
                        $('#fpType').html(cusName[i].invoicetype==1?'普通发票':'增值税发票')
                        //判断经销商是否有渠道优惠政策
                        $.post('{:url("hasyh")}',{jxs_id:keyword.id},function (data) {
                            //alert(data);
                            if(data.success){
                                $("#yhPolicy").bsSuggest('destroy')
                                $("#yhPolicy").bsSuggest({
                                    url: '{:url("yhPolicy")}?jxs_id='+keyword.id,
                                    effectiveFields: ["id", "title"],
                                    searchFields: [ "title"],
                                    effectiveFieldsAlias: {title: "名称"},
                                    ignorecase: true,
                                    showHeader: true,
                                    showBtn: false,     //不显示下拉按钮
                                    delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                                    idField: "id",
                                    keyField: "title",
                                    clearable: true
                                }).on('onDataRequestSuccess', function (e, result) {
                                    console.log('onDataRequestSuccess: ', result);
                                }).on('onSetSelectValue', function (e, keyword) {
                                    $('#yh_queding').find('.inin').html(keyword.key)
                                    $('#yh_queding').find('input').val(keyword.id)
                                    $('#yh_queding').show()
                                    $('#yh_input').hide()
                                    $('#yh_input').find('input').val('')
                                     qudaoyouhuipipei()
                                }).on('onUnsetSelectValue', function () {
                                    console.log("onUnsetSelectValue");
                                });
                                //关闭渠道优惠政策选择
                                $('#yh_queding .close').click(function () {
                                    $(this).closest('#yh_queding').hide().find('.inin').html('')
                                    $('#yh_queding').find('input').val('')
                                    $('#yh_input').show().find('input').val('')
                                })
                                //弹出渠道优惠政策树
                                $('#selectyh').off('click')
                                $('#selectyh').on('click',function () {
                                    top.layer.open({
                                        type:2,
                                        area:['60%','60%'],
                                        maxmin:true,
                                        content:'{:url("open/yhpolicy")}?jxs_id='+keyword.id,
                                        btn:['确定','关闭'],
                                        yes:function (i,o) {
                                            var a = $(o).find('iframe').contents()
                                            var id =  a.find("#renyuan").val();
                                            var name =  a.find("#renyuanname").val();
                                            if(id){
                                                $('#yh_queding').find('.inin').html(name)
                                                $('#yh_queding').find('input').val(id)
                                                $('#yh_queding').show()
                                                $('#yh_input').hide()
                                                $('#yh_input').find('input').val('')
                                            }
                                            //alert(1)
                                            top.layer.close(i)
                                        }
                                    })
                                    return  false
                                })
                                $('#hasyh').show()
                                $('#noyh').hide()
                            }else{
                                $('#hasyh').hide()
                                $('#noyh').show()
                            }

                            $('#hide1').show()
                        },'json')
                    }
                }*/

            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });

            $('#selectCus').off('click')
            //弹出经销商树
            $('#selectCus').on('click',function () {
                top.layer.open({
                    type:2,
                    area:['60%','60%'],
                    maxmin:true,
                    content: '{:url("open/net2")}',
                    btn:['确定','关闭'],
                    yes:function (i,o) {
                        var a = $(o).find('iframe').contents()
                        var id =  a.find("#renyuan").val();
                        var name =  a.find("#renyuanname").val();
                        if(id){
                            $('#cusName_queding').find('.inin').html(name)
                            $('#cusName_queding').find('input').val(id)
                            $('#cusName_queding').show()
                            $('#cusName_input').hide()
                            gonet(id);
                        }
                        top.layer.close(i)
                    }
                })
                return  false
            })
        }
    })
    $('#fanhui').on('click',function () {
        if(fr==1)
            location.href='{:url("index")}'
        else
            location.href="{:url('Workflowdb/index')}"
    })
    //删除
    $('.shanchu').on('click',function () {
        var link = $(this).data('link')
        $.post(link,function (data) {
            if(data.success){
                swal({title:data.msg},function () {
                    var oid=$("#id").val();
                    var qid=$("[name='yhPolicy']").val();
                    if(oid!=""&&qid!=""){
                        $.post('{:url("qdyhzcxz")}',{qdyh_id:qid,order_id:oid})
                    }
                        //
                    location.reload()
                })
            }else{
                swal(data.msg)
            }
        },'json')
    })
    //修改
    $('.xiugai').on('click',function () {
        var link = $(this).data('link')
        var jxs_id = $('input[name=cusName]').val()
        layer.open({
            type: 2,
            title: '修改明细',
            skin: 'layui-layer-rim', //加上边框
            area: ['800px', '500px'], //宽高
            content: link+'?jxs_id='+jxs_id
        });
    })
    $('.save').on('click',function () {
        $("#savet").val($(this).attr("savet"))
        var param = $(this).closest('form').serialize()
        //param.savet=$(this).attr("savet");
        $.post('',param,function (data) {
            if(data.success){
                swal({title:data.msg},function () {
                    location.href='{:url("index")}'
                })
            }else{
                swal(data.msg)
            }
        },'json')
        return false;
    })
    $(function () {
        //经销商搜索自动补全


        {if isset($data)&&$data.cusType==2}
        $("#cusName").bsSuggest({
            url: '{:url("bs/net")}',
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            $(this).data('cusName',escape(result.value))
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
            $('#cusName_queding').find('.inin').html(keyword.key)
            $('#cusName_queding').find('input').val(keyword.id)
            $('#cusName_queding').show()
            $('#cusName_input').hide()
            gonet(keyword.id)
            /*var cusName = $(this).data('cusName')
            cusName = unescape(cusName)
            for(var i = 0;i<cusName.length;i++){
                if(cusName[i].id==keyword.id){
                    $('[name=shdz]').val(cusName[i].lgs_rcv_addr)
                    $('[name=shr]').val(cusName[i].lgs_rcv_one)
                    $('[name=dh]').val(cusName[i].bs_rcv_phone)
                    // alert(cusName[i].invoicetype)
                    $('[name=fpType]:checked').val(cusName[i].invoicetype)
                    $('#fpType').html(cusName[i].invoicetype==1?'普通发票':'增值税发票')
                    //判断经销商是否有渠道优惠政策
                    $.post('{:url("hasyh")}',{jxs_id:keyword.id},function (data) {
                       // alert(data)
                        if(data.success){
                            $("#yhPolicy").bsSuggest('destroy')
                            $("#yhPolicy").bsSuggest({
                                url: '{:url("yhPolicy")}?jxs_id='+keyword.id,
                                effectiveFields: ["id", "title"],
                                searchFields: [ "title"],
                                effectiveFieldsAlias: {title: "名称"},
                                ignorecase: true,
                                showHeader: true,
                                showBtn: false,     //不显示下拉按钮
                                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                                idField: "id",
                                keyField: "title",
                                clearable: true
                            }).on('onDataRequestSuccess', function (e, result) {
                                console.log('onDataRequestSuccess: ', result);
                            }).on('onSetSelectValue', function (e, keyword) {
                                $('#yh_queding').find('.inin').html(keyword.key)
                                $('#yh_queding').find('input').val(keyword.id)
                                $('#yh_queding').show()
                                $('#yh_input').hide()
                                $('#yh_input').find('input').val('')
                                 qudaoyouhuipipei()
                                //查询渠道优惠政策限制规则
                                $.post('{:url("qdyhzcxz")}',{qdyh_id:keyword.id,order_id:$('#id').val()},function (data) {
                                    if(data.success){
                                       // location.reload()
                                    }
                                },'json')
                            }).on('onUnsetSelectValue', function () {
                                console.log("onUnsetSelectValue");
                            });
                            //关闭渠道优惠政策选择
                            $('#yh_queding .close').click(function () {
                                $(this).closest('#yh_queding').hide().find('.inin').html('')
                                $('#yh_queding').find('input').val('')
                                $('#yh_input').show().find('input').val('')
                            })
                            //弹出渠道优惠政策树
                            $('#selectyh').off('click')
                            $('#selectyh').on('click',function () {
                                top.layer.open({
                                    type:2,
                                    area:['60%','60%'],
                                    maxmin:true,
                                    content:'{:url("open/yhpolicy")}?jxs_id='+keyword.id,
                                    btn:['确定','关闭'],
                                    yes:function (i,o) {
                                        var a = $(o).find('iframe').contents()
                                        var id =  a.find("#renyuan").val();
                                        var name =  a.find("#renyuanname").val();
                                        if(id){
                                            $('#yh_queding').find('.inin').html(name)
                                            $('#yh_queding').find('input').val(id)
                                            $('#yh_queding').show()
                                            $('#yh_input').hide()
                                            $('#yh_input').find('input').val('')
                                        }
                                        top.layer.close(i)
                                    }
                                })
                                return  false
                            })
                            $('#hasyh').show()
                            $('#noyh').hide()
                        }else{
                            $('#hasyh').hide()
                            $('#noyh').show()
                        }

                        $('#hide1').show()
                    },'json')
                }
            }
            */
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

        $('#selectCus').off('click')
        //弹出经销商树
        $('#selectCus').on('click',function () {
            top.layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content: '{:url("open/net2")}',
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var id =  a.find("#renyuan").val();
                    var name =  a.find("#renyuanname").val();
                    if(id){
                        $('#cusName_queding').find('.inin').html(name)
                        $('#cusName_queding').find('input').val(id)
                        $('#cusName_queding').show()
                        $('#cusName_input').hide()
                        gonet(id);
                    }
                    top.layer.close(i)
                }
            })
            return  false
        })
        //经销商搜索自动补全--修改时
        {if request()->param("id")}
        $("#yhPolicy").bsSuggest({
            url: '{:url("yhPolicy",["jxs_id"=>$data.jxs])}',
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
            $('#yh_queding').find('.inin').html(keyword.key)
            $('#yh_queding').find('input').val(keyword.id)
            $('#yh_queding').show()
            $('#yh_input').hide()
            $('#yh_input').find('input').val('')
             qudaoyouhuipipei()
            //查询渠道优惠政策限制规则
            /*$.post('{:url("qdyhzcxz")}',{qdyh_id:keyword.id,order_id:$('#id').val()},function (data) {
                if(data.success){
                    //location.reload()
                }
            },'json')*/
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

        //关闭渠道优惠政策选择
        $('#yh_queding .close').click(function () {
            $(this).closest('#yh_queding').hide().find('.inin').html('')
            $('#yh_queding').find('input').val('')
            $('#yh_input').show().find('input').val('')
            clearyh();
        })

        //弹出渠道优惠政策树
        $('#selectyh').click(function () {
            layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("open/yhpolicy",["jxs_id"=>$data.jxs])}',
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var id =  a.find("#renyuan").val();
                    var name =  a.find("#renyuanname").val();
                    if(id){
                        $('#yh_queding').find('.inin').html(name)
                        $('#yh_queding').find('input').val(id)
                        $('#yh_queding').show()
                        $('#yh_input').hide()
                        $('#yh_input').find('input').val('')
                        qudaoyouhuipipei()
                    }
                    layer.close(i)
                }
            })
            return  false
        })
        {/if}
        {else}
        $("#cusName").bsSuggest({
            url: link1,
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            $(this).data('cusName',escape(result.value))
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
            $('#cusName_queding').find('.inin').html(keyword.key)
            $('#cusName_queding').find('input').val(keyword.id)
            $('#cusName_queding').show()
            $('#cusName_input').hide()
             gojxs(keyword.id)

        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

        $('#selectCus').off('click')
        //弹出经销商树
        $('#selectCus').click(function () {
            top.layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:link2,
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var id =  a.find("#renyuan").val();
                    var name =  a.find("#renyuanname").val();
                    if(id){
                        $('#cusName_queding').find('.inin').html(name)
                        $('#cusName_queding').find('input').val(id)
                        $('#cusName_queding').show()
                        $('#cusName_input').hide()

                       gojxs(id)
                    }
                    top.layer.close(i)
                }
            })
            return  false
        })

        //经销商搜索自动补全--修改时
        {if request()->param("id")}
        $("#yhPolicy").bsSuggest({
            url: '{:url("yhPolicy",["jxs_id"=>$data.cusName])}',
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
            $('#yh_queding').find('.inin').html(keyword.key)
            $('#yh_queding').find('input').val(keyword.id)
            $('#yh_queding').show()
            $('#yh_input').hide()
            $('#yh_input').find('input').val('')
             qudaoyouhuipipei()
            //查询渠道优惠政策限制规则
            /*$.post('{:url("qdyhzcxz")}',{qdyh_id:keyword.id,order_id:$('#id').val()},function (data) {
                if(data.success){
                    //location.reload()
                }
            },'json')*/
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

        //关闭渠道优惠政策选择
        $('#yh_queding .close').click(function () {
            $(this).closest('#yh_queding').hide().find('.inin').html('')
            $('#yh_queding').find('input').val('')
            $('#yh_input').show().find('input').val('')
            clearyh();
        })

        //弹出渠道优惠政策树
        $('#selectyh').click(function () {
            layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("open/yhpolicy",["jxs_id"=>$data.cusName])}',
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var id =  a.find("#renyuan").val();
                    var name =  a.find("#renyuanname").val();
                    if(id){
                        $('#yh_queding').find('.inin').html(name)
                        $('#yh_queding').find('input').val(id)
                        $('#yh_queding').show()
                        $('#yh_input').hide()
                        $('#yh_input').find('input').val('')
                        qudaoyouhuipipei()
                    }
                    layer.close(i)
                }
            })
            return  false
        })
        {/if}
        {/if}


        //关闭经销商选择
        $('#cusName_queding .close').click(function () {
            $(this).closest('#cusName_queding').hide().find('.inin').html('')
            $('#cusName_input').show().find('input').val('')
        })
    })
    function back() {
        history.go(-1)
    }

    laydate({
        elem: "#startTime",
        event: "focus"
    })

    var AgencyName = $("#AgencyName");
    sousuo(AgencyName)

    function sousuo(id) {
        id.bsSuggest({
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: true, //以分隔符号分割的多关键字支持
            separator: ",", //多关键字支持时的分隔符，默认为空格
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            url: 'http://unionsug.baidu.com/su?p=3&t=' + (new Date()).getTime() + '&wd=',
            /*优先从url ajax 请求 json 帮助数据，注意最后一个参数为关键字请求参数*/
            jsonp: 'cb',
            /*如果从 url 获取数据，并且需要跨域，则该参数必须设置*/
            processData: function (json) { // url 获取数据时，对数据的处理，作为 getData 的回调函数
                var i, len, data = {
                    value: []
                };
                if (!json || !json.s || json.s.length === 0) {
                    return false;
                }

                // console.log(json);
                len = json.s.length;

                jsonStr = "{'value':[";
                for (i = 0; i < len; i++) {
                    data.value.push({
                        word: json.s[i]
                    });
                }
                data.defaults = 'baidu';

                //字符串转化为 js 对象
                return data;
            }
        });

    }

    $("#addsall").click(function () {
        if ($("[name=cusName]").val() == "") {
            swal("", "客户名称不能为空！", "error")
        }   else if ($("[name=shdz]").val() == "") {
            swal("", "收货地址不能为空！", "error")
        } else if ($("[name=shr]").val() == "") {
            swal("", "收货人不能为空！", "error")
        } else if ($("[name=dh]").val() == "") {
            swal("", "电话不能为空！", "error")
        } else {
            var jxs_id = $('[name=cusName]').val()
            var yhPolicy = $('[name=yhPolicy]').val()
            layer.open({
                type: 2,
                title: '添加销售订单明细',
                skin: 'layui-layer-rim', //加上边框
                area: ['900px', '500px'], //宽高
                maxmin:true,
                content: '{:url("add_Dd_detail")}?jxs_id='+jxs_id
            });
        }
    })

    //添加货补
    $("#addhuobu").click(function () {
        var id = $('#id').val()
        if($('#id').val()==''){
            swal("", "请先添加订货明细！", "error")
            return false
        }
        if ($("#gys").val() == "") {
            swal("", "供应商不能为空！", "error")
        } else if ($("#wlKind").val() == "") {
            swal("", "物料类别不能为空！", "error")
        } else if ($("#gysAddr").val() == "") {
            swal("", "供应商地址不能为空！", "error")
        } else if ($("#concact").val() == "") {
            swal("", "联系人不能为空！", "error")
        } else if ($("#tell").val() == "") {
            swal("", "电话不能为空！", "error")
        } else if ($("#them").val() == "") {
            swal("", "主题(采购原因)不能为空！", "error")
        } else {
            var cusName = $('[name=cusName]').val()
            layer.open({
                type: 2,
                title: '添加货补订单明细',
                skin: 'layui-layer-rim', //加上边框
                area: ['800px', '500px'], //宽高
                content: '{:url("buhuo_detail")}?id='+id+'&jxs_id='+cusName
            });
        }
    })
    $("#addbuhuo").click(function () {
        var id = $('#id').val()
        var cusName = $('[name=cusName]').val()
        if (cusName == "") {
            swal("", "请选择客户名称！", "error")
            return false
        }
        layer.open({
            type: 2,
            title: '添加补费订单明细',
            skin: 'layui-layer-rim', //加上边框
            area: ['800px', '500px'], //宽高
            content: '{:url("bufei_Dd_detail")}?id='+id+'&jxs_id='+cusName
        });
    })
</script>
</body>

</html>
<!-- Web Uploader -->
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script>
    // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

        var ids = [];
        uploader = WebUploader.create({

            // 不压缩image
            resize: false,

            // swf文件路径
            swf: BASE_URL + '/js/Uploader.swf',

            // 文件接收服务端。
            server: '{:url("upload/fileupload")}',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker'
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });

    });
</script>